<?php

class GetOpenclass implements iController {

    public function output($queryArgs) {
        global $cmsdb;
        
        //TODO 需要加时间过滤，过期的课堂不再返回。
        $sql = 'SELECT co.detail_pic,co.cover_pic,co.id course_id,cl.id class_id,cl.lector_id,cl.start_time,cl.end_time
        FROM data_live_course co ,data_live_class cl,relationship_live_class_and_course re
        where re.class_id = cl.id AND re.course_id = co.id AND co.type_id=1 AND cl.end_time >=:mDay AND publish_status =:mStatus
        ORDER BY co.id DESC';


        $courseList = $cmsdb->getResults($sql,array(
            'mStatus' => 'publish',
            'mDay' => date('Y-m-d H:i:s')));

        $list = array();

        $now = time();
        if (!empty($courseList)) {

            foreach ($courseList as $course) {

                $isOnAir = 0;
                if (($now+10*60) >= strtotime($course->start_time) && $now <= strtotime($course->end_time)){
                    $isOnAir = 1;
                }
                $list[] = array(
                    'class_id'   => intval($course ->class_id),
                    'course_id'  => intval($course ->course_id),
                    'lector_id'  => intval($course->lector_id),
                    'cover_pic'  => getSecureUrl($course->cover_pic),
                    'is_onair'   => $isOnAir
                );
            }
        }

        return genOutput(1,array('classes' => $list));
    }
}